package com.zisu.springbootsource.listener;

import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.core.annotation.Order;

/**
 * @Author: 蔡翔
 * @Date: 2020/5/7 19:34
 * @Version 1.0
 */
@Order(3)
public class ThirdListener implements SmartApplicationListener {

    //这里写 我们对哪些事件感兴趣。
    @Override
    public boolean supportsEventType(Class<? extends ApplicationEvent> aClass) {
        //ApplicationStartedEvent或者是 系统准备好了的 的事件
        return ApplicationStartedEvent.class.isAssignableFrom(aClass) || ApplicationPreparedEvent.class.isAssignableFrom(aClass);
    }

    //当事件发生的 时候 执行什么
    @Override
    public void onApplicationEvent(ApplicationEvent applicationEvent) {
        System.out.println("hello third");
    }
}
